package com.slz3.business.module.wmsManagement.wmsPurchaseOrderThree.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderThree.domain.WmsPurchaseOrderThree;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderThree.domain.WmsPurchaseOrderThreeFactory;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderThree.steward.WmsPurchaseOrderThreeSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Service
public class WmsPurchaseOrderThreeServiceImpl implements WmsPurchaseOrderThreeService {
    @Override
    public WmsPurchaseOrderThree save(WmsPurchaseOrderThree wmsPurchaseOrderThree) {
        return Repositorys.wmsPurchaseOrderThree.save(WmsPurchaseOrderThreeFactory.initBaseFields(wmsPurchaseOrderThree));
    }

    @Override
    public Page<WmsPurchaseOrderThree> page(MultiValueMap<String, String> params) {
        Page<WmsPurchaseOrderThree> wmsPurchaseOrderThreePage = Repositorys.wmsPurchaseOrderThree.findAll(
                WmsPurchaseOrderThreeSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return wmsPurchaseOrderThreePage;
    }


    @Override
    public WmsPurchaseOrderThree modify(WmsPurchaseOrderThree wmsPurchaseOrderThreeNew) {
        return Repositorys.wmsPurchaseOrderThree.saveAndFlush(WmsPurchaseOrderThreeFactory.initBaseFields(wmsPurchaseOrderThreeNew));
    }

    @Override
    public Optional<WmsPurchaseOrderThree> single(UUID uuid) {
        return Repositorys.wmsPurchaseOrderThree.findById(uuid);
    }

    @Override
    public List<WmsPurchaseOrderThree> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.wmsPurchaseOrderThree.findAllById(uuids);
    }

    @Override
    public List<WmsPurchaseOrderThree> delete(List<WmsPurchaseOrderThree> wmsPurchaseOrderThreeList) {
        wmsPurchaseOrderThreeList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            WmsPurchaseOrderThreeFactory.initBaseFields(item);
        });
        return Services.wmsPurchaseOrderThreeTransactional.batchModify(wmsPurchaseOrderThreeList);
    }

}
